function [ subjectinfo ] = analyzeVisualResponsivenessFull_PublishResults( subjectinfo )
%ANALYZEVISUALRESPONSIVENESS Analyzes the data for visual responsiveness

% STEP 3
subjectinfo = Step3(subjectinfo);

subjectinfo.Save;

end

%% Step 3: Plot and save
function [s] = Step3(s)
% Plot the wave data
figures = [];
for x=1:length(s.Analyses.VisualResponsiveness.Sets)
    
    load(s.Analyses.VisualResponsiveness.Sets(x).WavedataFilename);

    [ figResponsiveness figVariability ] = plotResponsivenessAndVariability( ...
        waveStimulus.powspctrm, waveRest.powspctrm, ...
        s.Analyses.VisualResponsiveness.Sets(x).Description, ...
        electrodeLabels, frequenciesOfInterest);
    figures = [figures; figResponsiveness, figVariability];
end

% Write the figures to files

if ~exist([s.Analyses.VisualResponsiveness.Filepath 'Results\'], 'dir')
    mkdir(s.Analyses.VisualResponsiveness.Filepath, 'Results');
end

for x=1:length(s.Analyses.VisualResponsiveness.Sets)

    printFigureA4Multiformat(figures(x,1), ...
        [s.Analyses.VisualResponsiveness.Filepath 'Results\'], ...
        [s.Analyses.VisualResponsiveness.Sets(x).Description ' - Responsiveness']);

    printFigureA4Multiformat(figures(x,2), ...
        [s.Analyses.VisualResponsiveness.Filepath 'Results\'], ...
        [s.Analyses.VisualResponsiveness.Sets(x).Description ' - Variability']);

end

% Close the figures

for x=1:length(s.Analyses.VisualResponsiveness.Sets)
    close(figures(x,1));
    close(figures(x,2));
end
end